package com.medusa.aps.business.modules.basic.mp.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.medusa.aps.business.model.BaseEntity;
import com.medusa.aps.business.modules.basic.model.WorkPeriod;
import com.medusa.aps.business.common.mp.FastJson2TypeHandler;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;

/**
 * 工作日历实体类
 *
 * @author yuxh
 * @since 2023-08-14 17:37:53
 */
@Data
@Accessors(chain = true)
@TableName(autoResultMap = true)
@EqualsAndHashCode(callSuper = true)
public class WorkingCalendar extends BaseEntity<WorkingCalendar> {
    /**
     * 主键
     */
    @Schema(description = "主键")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 班制 id
     */
    @Schema(description = "班制 id")
    private Integer classId;

    /**
     * 设备组id
     */
    @Schema(description = "设备id")
    private Long deviceId;

    /**
     * 日期
     */
    @Schema(description = "日期")
    @TableField(value = "`date`")
    private LocalDate date;

    /**
     * 工作日
     */
    @Schema(description = "工作日")
    private Integer workingDay;
    /**
     * 工作时段id
     */
    @Schema(description = "工作时段id")
    private Integer workingTimeId;
    /**
     * 是否能被编辑
     */
    @TableField(exist = false)
    @Schema(description = "是否能被编辑")
    private Boolean isEdit;

    /**
     * 工作时段信息
     */
    @Schema(description = "工作时段信息")
    @TableField(typeHandler = FastJson2TypeHandler.class)
    private WorkingTimeInfo periodInfo;

    /**
     * 获取主键值
     *
     * @return 主键值
     */
    @Override
    public Serializable pkVal() {
        return this.id;
    }


    /**
     * 工作时段信息类
     */
    @Getter
    @Setter
    @ToString
    @Accessors(chain = true)
    @TableName(autoResultMap = true)
    public static class WorkingTimeInfo implements Serializable {
        /**
         * 时段名称
         */
        @Schema(description = "时段名称")
        private String name;

        /**
         * 时段时间
         */
        @Schema(description = "时间段列表")
        private List<WorkPeriod> times;
    }
}

